package com.example.util.controller;

import com.alibaba.fastjson.JSON;
import com.example.util.mq.disruptor.FileReqData;
import com.example.util.mq.disruptor.service.DisruptorMqService;
import com.example.util.service.TaskService;
import com.example.util.util.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.util.*;

@RestController
@Slf4j
public class TempWhiteListController {

    private static Set<String> dataSet = new HashSet<>();

    @Value("${terminal.manage.url:http://10.10.183.121:16302/ue/v1/capability/5gmsg/sip:106505110000195559@botplatform.rcs.chinamobile.com\"}")
    private String terminalManageUrl;

    @Autowired
    private DisruptorMqService disruptorMqService;

    @Autowired
    private TaskService taskService;



    /**
     * 传入读取目录和写入目录进行手机号读取
     *
     * @param fileDir
     * @param fileWriterDir
     * @return
     */
    @GetMapping(path = "/task/add")
    Map<String, Object> taskAdd(@RequestParam("fileDir") String fileDir, @RequestParam("fileWriterDir") String fileWriterDir) {

        Map<String, Object> response = new HashMap<>();
        File file = new File(fileDir);
        if (file.exists()) {
            FileReqData fileReqData = new FileReqData();
            fileReqData.setReadDir(fileDir);
            fileReqData.setWriteDir(fileWriterDir);
            fileReqData.setTerminalManageUrl(terminalManageUrl);
            fileReqData.setBusiType(1);
            disruptorMqService.sendVariableMsg(JSON.toJSONString(fileReqData));
            response.put("code", 0);
            response.put("resaon", "成功");
            return response;

        } else {
            log.info("文件不存在!");
            response.put("code", -100);
            response.put("resaon", "文件不存在");
            return response;
        }
    }

    /**
     * 生成0-9除号段的内容并存储文件
     * 10^8
     *
     * @param fileWriterDir
     * @return
     */
    @GetMapping(path = "/task/write")
    Map<String, Object> writeEightFile(@RequestParam("fileWriterDir") String fileWriterDir) {

        Map<String, Object> response = new HashMap<>();
        FileReqData fileReqData = new FileReqData();
        fileReqData.setWriteDir(fileWriterDir);
        fileReqData.setTerminalManageUrl(terminalManageUrl);
        fileReqData.setBusiType(2);
        disruptorMqService.sendVariableMsg(JSON.toJSONString(fileReqData));
        response.put("code", 0);
        response.put("resaon", "成功");
        return response;
    }

    /**
     * 生成手机号并组装，调用接口去查询
     *
     * @param fileWriterDir
     * @return
     */
    @GetMapping(path = "/task/assertAndSearch")
    Map<String, Object> writeFileV2(@RequestParam("fileDir") String fileDir, @RequestParam("fileWriterDir") String fileWriterDir, @RequestParam("cardType") String cardType) {

        return taskService.writeFileV2(fileDir,fileWriterDir,cardType);
    }

    /**
     * 生成手机号并组装，调用接口去查询
     *
     * @param fileDir
     * @return
     */
    @GetMapping(path = "/task/bachTask")
    Map<String, Object> chooseTask(@RequestParam("fileDir") String fileDir, @RequestParam("name") String name) {
        Map<String, Object> response = new HashMap<>();
        Boolean aBoolean = FileUtil.splitDirByTask(fileDir, 10, name);
        response.put("code", aBoolean);
        return response;
    }

}



